const connection = require('../app/batabase');

/**
 * tableName - 操作的表名
 * resourceId - 要修改或删除的内容的id
 * userId - 此用户的id
 */
class AuthService {
    async checkResource(tableName, resourceId, userId) {  
        try {                
            const statement =  `SELECT * FROM ${tableName} WHERE id = ? AND user_id = ?;`;
            const [result] = await connection.execute(statement, [resourceId, userId]);
            // console.log(result);      //返回的是查到的这条数据的所有字段信息
            return result.length === 0 ? false : true;
        } catch (error) {
            console.log(error);
        }
    }
}

module.exports = new AuthService();